package db;

import java.util.List;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.LockMode;
import org.springframework.context.ApplicationContext;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

/**
 * A data access object (DAO) providing persistence and search support for
 * Forderpurmat entities. Transaction control of the save(), update() and
 * delete() operations can directly support Spring container-managed
 * transactions or they can be augmented to handle user-managed Spring
 * transactions. Each of these methods provides additional information for how
 * to configure it for the desired type of transaction control.
 * 
 * @see db.Forderpurmat
 * @author MyEclipse Persistence Tools
 */

public class ForderpurmatDAO extends HibernateDaoSupport {
	private static final Log log = LogFactory.getLog(ForderpurmatDAO.class);
	// property constants
	public static final String FOR_ORDER_ID = "forOrderId";
	public static final String MATERIAL_CODE = "materialCode";
	public static final String MATERIAL_NAME = "materialName";
	public static final String ORDER_NUM = "orderNum";
	public static final String ORDER_PRICE = "orderPrice";
	public static final String MATERIAL_ID = "materialId";
	public static final String PRO_NAME = "proName";
	public static final String PRO_CODE = "proCode";
	public static final String PRO_ID = "proId";

	protected void initDao() {
		// do nothing
	}

	public void save(Forderpurmat transientInstance) {
		log.debug("saving Forderpurmat instance");
		try {
			getHibernateTemplate().save(transientInstance);
			log.debug("save successful");
		} catch (RuntimeException re) {
			log.error("save failed", re);
			throw re;
		}
	}

	public void delete(Forderpurmat persistentInstance) {
		log.debug("deleting Forderpurmat instance");
		try {
			getHibernateTemplate().delete(persistentInstance);
			log.debug("delete successful");
		} catch (RuntimeException re) {
			log.error("delete failed", re);
			throw re;
		}
	}

	public Forderpurmat findById(java.lang.Integer id) {
		log.debug("getting Forderpurmat instance with id: " + id);
		try {
			Forderpurmat instance = (Forderpurmat) getHibernateTemplate().get(
					"db.Forderpurmat", id);
			return instance;
		} catch (RuntimeException re) {
			log.error("get failed", re);
			throw re;
		}
	}

	public List findByExample(Forderpurmat instance) {
		log.debug("finding Forderpurmat instance by example");
		try {
			List results = getHibernateTemplate().findByExample(instance);
			log.debug("find by example successful, result size: "
					+ results.size());
			return results;
		} catch (RuntimeException re) {
			log.error("find by example failed", re);
			throw re;
		}
	}

	public List findByProperty(String propertyName, Object value) {
		log.debug("finding Forderpurmat instance with property: "
				+ propertyName + ", value: " + value);
		try {
			String queryString = "from Forderpurmat as model where model."
					+ propertyName + "= ?";
			return getHibernateTemplate().find(queryString, value);
		} catch (RuntimeException re) {
			log.error("find by property name failed", re);
			throw re;
		}
	}

	public List findByForOrderId(Object forOrderId) {
		return findByProperty(FOR_ORDER_ID, forOrderId);
	}

	public List findByMaterialCode(Object materialCode) {
		return findByProperty(MATERIAL_CODE, materialCode);
	}

	public List findByMaterialName(Object materialName) {
		return findByProperty(MATERIAL_NAME, materialName);
	}

	public List findByOrderNum(Object orderNum) {
		return findByProperty(ORDER_NUM, orderNum);
	}

	public List findByOrderPrice(Object orderPrice) {
		return findByProperty(ORDER_PRICE, orderPrice);
	}

	public List findByMaterialId(Object materialId) {
		return findByProperty(MATERIAL_ID, materialId);
	}

	public List findByProName(Object proName) {
		return findByProperty(PRO_NAME, proName);
	}

	public List findByProCode(Object proCode) {
		return findByProperty(PRO_CODE, proCode);
	}

	public List findByProId(Object proId) {
		return findByProperty(PRO_ID, proId);
	}

	public List findAll() {
		log.debug("finding all Forderpurmat instances");
		try {
			String queryString = "from Forderpurmat";
			return getHibernateTemplate().find(queryString);
		} catch (RuntimeException re) {
			log.error("find all failed", re);
			throw re;
		}
	}

	public Forderpurmat merge(Forderpurmat detachedInstance) {
		log.debug("merging Forderpurmat instance");
		try {
			Forderpurmat result = (Forderpurmat) getHibernateTemplate().merge(
					detachedInstance);
			log.debug("merge successful");
			return result;
		} catch (RuntimeException re) {
			log.error("merge failed", re);
			throw re;
		}
	}

	public void attachDirty(Forderpurmat instance) {
		log.debug("attaching dirty Forderpurmat instance");
		try {
			getHibernateTemplate().saveOrUpdate(instance);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}

	public void attachClean(Forderpurmat instance) {
		log.debug("attaching clean Forderpurmat instance");
		try {
			getHibernateTemplate().lock(instance, LockMode.NONE);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}

	public static ForderpurmatDAO getFromApplicationContext(
			ApplicationContext ctx) {
		return (ForderpurmatDAO) ctx.getBean("ForderpurmatDAO");
	}
}